package com.agung.wonogirimaps.adapter;

import java.util.ArrayList;

import com.agung.wonogirimaps.util.Utils;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class GalleryPagerAdapter extends PagerAdapter
{
	private Context				context;
	private ArrayList<String>	arrayGambar;
	private ImageLoader			imgLoader;

	public GalleryPagerAdapter(Context context, ArrayList<String> arrayGambar)
	{
		this.context = context;
		this.arrayGambar = arrayGambar;
		imgLoader = ImageLoader.getInstance();
		imgLoader.init(Utils.getImgConfig(context));
	}

	@Override
	public int getCount()
	{
		// TODO Auto-generated method stub
		return arrayGambar.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1)
	{
		return arg0 == ((ImageView) arg1);
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position)
	{
		ImageView imgView = new ImageView(context);
		imgLoader.displayImage(arrayGambar.get(position), imgView,
				Utils.getImgOpt());

		((ViewPager) container).addView(imgView, 0);

		return imgView;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object)
	{
		((ViewPager) container).removeView((ImageView) object);
	}

	@Override
	public Parcelable saveState()
	{
		// TODO Auto-generated method stub
		return super.saveState();
	}

}
